﻿using System;
using System.Windows.Forms;
using Extensions;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.Controls;

namespace Tailord
{
    public partial class Firma : XForm
    {
        public Firma()
        {
            InitializeComponent();
        }

        BindingSource bsF, bsB, bsU;
        private void Firma_Load(object sender, EventArgs e)
        {
            MainToolbar.Visible = true;
            bbiHideDeleted.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;

            TAM.FirmaTableAdapter = new TailordDS.AppDSTableAdapters.FirmaTableAdapter();
            TAM.BayiTableAdapter = new TailordDS.AppDSTableAdapters.BayiTableAdapter();
            TAM.UserTableAdapter = new TailordDS.AppDSTableAdapters.UserTableAdapter();

            bsF = new BindingSource(ds, "Firma");
            bsB = new BindingSource(bsF, "FK_Firma_Bayi_Firmad");
            bsU = new BindingSource(bsB, "FK_Bayi_User_Bayid");
            AddBsToList(bsF, bsB, bsU);
            bsF.Filter = "FirmaId not in (4)";

            InitGridView(gvFirma, bsF);
            InitGridView(gvBayi, bsB);
            InitGridView(gvUser, bsU);

            gvFirma.ViewCaption = "Firmalar";
            gvFirma.OptionsView.ShowViewCaption = true;
            gvFirma.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;
            gvFirma.MakeRowSelectable();

            gvBayi.ViewCaption = "Bayiler";
            gvBayi.OptionsView.ShowViewCaption = true;
            gvBayi.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;
            gvBayi.YanYanaGetir("MagazaKodu:Lokasyon");
            gvBayi.MakeRowSelectable();

            gvUser.ViewCaption = "Kullanıcılar";
            gvUser.OptionsView.ShowViewCaption = true;
            gvUser.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;

            gvBayi.AddSummary();
            gvUser.AddSummary();

            gvFirma.MakeColumnInvisible("Logo", "Path");
            gvBayi.MakeColumnInvisible("FirmaId");
            gvUser.MakeColumnInvisible("BayiId", "LastLogin");

            splitContainerControl1.SizeChanged += MySizeChanged;
            splitContainerControl2.SizeChanged += MySizeChanged;

            GetDetails("Firma;Bayi;User", "GetFirmaBayiUser");

            RepositoryItemComboBox riPrepacking = new RepositoryItemComboBox();
            riPrepacking.Items.AddRange(new object[] { "İç Piyasa", "Dış Piyasa" });
            riPrepacking.TextEditStyle = TextEditStyles.DisableTextEditor;
            gvFirma.Columns["Mensei"].ColumnEdit = riPrepacking;

            gvFirma.FocusedRowChanged += gvFirma_FocusedRowChanged;
            BestFit();

            bbiSave.ItemClick+=bbiSave_ItemClick;
        }

        void gvFirma_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            //Lbl.Text = gvFirma.GetFocusedRowCellDisplayText("Ad");
            BestFit();
        }

        void BestFit()
        {
            gvFirma.BestFitColumns();
            gvFirma.Columns["FirmaAdresi"].Width = 200;
            gvBayi.BestFitColumns();
            gvUser.BestFitColumns();
        }

        /*
        void gv_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            if (gv.GetRowCellValue(e.RowHandle, del) != null)
                if (gv.GetRowCellValue(e.RowHandle, del) != DBNull.Value)
                    if ((bool)(gv.GetRowCellValue(e.RowHandle, del)))
                        e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Strikeout);

        }
        */

        public void bbiSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Save();
        }


    }
}
